#!/bin/bash
:<<!
上传文件到该目录下app_info.json中对应参数的脚本
!
#sh upload_continue.sh -ipa "${ipa_file_path}" --shouldUploadToPgyer ${ShouldUploadToPgyer} --shouldBackupToCos ${ShouldBackupToCos} --shouldUploadToAppStore ${ShouldUploadToAppStore} -d "${ChangeLog}" -np $NotificatePeople
#sh upload_continue.sh  -ipa "~/Desktop/dianzan.svg" --shouldUploadToPgyer true --shouldBackupToCos false --shouldUploadToAppStore false -d "更新说明略" -np none
# 更新说明有换行，暂时还不支持
User=`whoami`

JQ_EXEC=`which jq`

# shell 参数具名化
show_usage="args: [-appInfoJsonF ,-ipa, -supPgyer, -supCos, -supAppStore, -d, -np]\
                                  [--app-info-json-file=, --ipa-file-path=, --shouldUploadToPgyer=,--shouldBackupToCos=,--shouldUploadToAppStore=, --update-description=, --notificate-forPeople=]"

while [ -n "$1" ]
do
        case "$1" in
                -appInfoJsonF|--app-info-json-file) FILE_PATH=$2; shift 2;;
                -ipa|--ipa-file-path) ipa_file_path=$2; shift 2;;
                -supPgyer|--shouldUploadToPgyer) ShouldUploadToPgyer=$2; shift 2;;
                -supCos|--shouldBackupToCos) ShouldBackupToCos=$2; shift 2;;
                -supAppStore|--shouldUploadToAppStore) ShouldUploadToAppStore=$2; shift 2;;
                -d|--update-description) ChangeLog=$2; shift 2;;
                -np|--notificate-forPeople) NotificatePeople=$2; shift 2;;
                --) break ;;
                *) echo $1,$2,$show_usage; break ;;
        esac
done

ShouldBackupToLocal="true"


exit_script() { # 退出脚本的方法，省去当某个步骤失败后，还去继续多余的执行其他操作
    exit 1
}


#if [ $# != 5 ]; then
#    echo "当前参数个数$#，必须为5个，请设置更新说明"
#    exit 1
#fi

echo "FILE_PATH=$FILE_PATH"
echo "ipa_file_path=$ipa_file_path"
echo "ChangeLog=$ChangeLog"
echo "NotificatePeople=$NotificatePeople"
echo "User=$User"
#echo "结束"

echo "$0检查本分支是否可以打包指定环境"
#[在shell脚本中验证JSON文件的语法](https://qa.1r1g.com/sf/ask/2966952551/)
#cat app_info.json
source ./a_function.sh ./
check_jsonFile_valid ${FILE_PATH}

echo "ShouldUploadToPgyer=${ShouldUploadToPgyer}"
echo "ShouldBackupToCos=${ShouldBackupToCos}"
echo "ShouldUploadToAppStore=${ShouldUploadToAppStore}"
sh uploadArgSetForEnv_all.sh -appInfoF ${FILE_PATH} --shouldUploadToPgyer ${ShouldUploadToPgyer} --shouldBackupToCos ${ShouldBackupToCos} --shouldUploadToAppStore ${ShouldUploadToAppStore}
if [ $? != 0 ]; then
    sh noti_new_package.sh -appInfoF ${FILE_PATH} --log-robottype "error"
    exit_script
fi

sh noti_new_package.sh -appInfoF ${FILE_PATH} -ll "包选择结束，准备上传"

sh all_packing_upload.sh -envInfoF "${FILE_PATH}" -ipa "${ipa_file_path}"
if [ $? != 0 ]; then
    echo "所有脚本执行结束"
    exit 1
fi

:<<!
if [ "${PlatformType}" == "Android" ] && [ "${PackageTargetType}" == "formal" ] && [ "${PackageNetworkType}" == "product" ]; then
    cd $WORKSPACE/bulidScript
    sh noti_new_package.sh -appInfoF ${FILE_PATH} -ll "这是Android待加固的审核包,下面额外执行加固操作,并输出渠道包\n${ChangeLog}"
    sh hardeningApk.sh "${ipa_file_path}"
fi
!
echo "所有脚本执行结束"











